package proxy.JDKDynamicProxy;

import proxy.staticProxy.TestFunctionSpendTime;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author wmin
 */
public class TenantHandler<T> implements InvocationHandler {
    //持有的被代理类的引用
    private T target;

    //被代理类赋值
    public TenantHandler(final T target) {
        this.target = target;
    }

    //通过代理类去执行代理类的方法时，都先调用此方法
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        TestFunctionSpendTime.start = System.currentTimeMillis();
        System.out.println("谈论价钱");
        method.invoke(target,args);
        System.out.println("交接钥匙");
        TestFunctionSpendTime.end = System.currentTimeMillis();
        TestFunctionSpendTime.display();
        return null;
    }
}
